package com.JL.test;


import com.JL.engine.model.*;
import com.JL.engine.util.AssetsLoader;
import com.JL.window.GameWindow;

import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.geom.Point2D;

public class TankGame extends GameWindow {
    private Entity player;
    private Entity mouse;
    TankGame(){
        setTitle("坦克大战");
    }
    @Override
    public  void initGame(){
        AssetsLoader.initAssetsLoader("D:\\JavaProjects\\项目\\test__03\\assets");{
            InitData data = new InitData();
            data.setPosition(100,100);
            data.setSize(100,100);
            data.putOption("id",0);
            data.putOption("type",GameType.PLAYER);
            createEntity("player",data);
        }
        {
            InitData data = new InitData();
            data.setPosition(200,200);
            data.setSize(100,100);
            data.putOption("id",1);
            data.putOption("type",GameType.ENEMY);
            createEntity("player",data);
        }
    }
    @Override
    public void initInput(){
        onKey(KeyEvent.VK_UP, e->{
            Entity entity = getGameWorld().getEntityById(0);
            MoveComponent component = entity.getComponent(MoveComponent.class);
            component.moveUp(10);
        });
        onKey(KeyEvent.VK_DOWN,e->{
            Entity entity = getGameWorld().getEntityById(0);
            MoveComponent component = entity.getComponent(MoveComponent.class);
            component.moveDown(10);
        });
        onKey(KeyEvent.VK_LEFT,e->{
            Entity entity = getGameWorld().getEntityById(0);
            MoveComponent component = entity.getComponent(MoveComponent.class);
            component.moveLeft(10);
        });
        onKey(KeyEvent.VK_RIGHT,e->{
            Entity entity = getGameWorld().getEntityById(0);
            MoveComponent component = entity.getComponent(MoveComponent.class);
            component.moveRight(10);
        });
    }
    @Override
    public void collision(){
        addCollisionHandler(GameType.PLAYER,GameType.ENEMY,new CollisionHandler(){

            @Override
            public void onCollision(Entity source, Entity target) {

            }

            @Override
            public void onCollision(Entity source, Entity target, HotRectangle sourceHot, HotRectangle targetHot){
                System.out.printf("玩家的[%s]碰撞到了敌人的[%s]\n",sourceHot.getName(),targetHot.getName());
            }
        });
    }
    public static void main(String[] args){
        TankGame tankGame = new TankGame();
    }}